package com.tony.xml;

import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.Iterator;

/**
 * @version V1.0  </br>
 * @ClassName DOM4jDemo1 </br>
 * @Description TODO  </br>
 * @Author tonywang</br>
 * @DATE 3/8/2019 10:17 AM</br>
 */
public class DOM4jDemo1 {
    public void DOM4jDemo() {
        long lasting = System.currentTimeMillis();
        File file = new File("C:\\Users\\tonywang\\Desktop\\springboot\\springBoot\\src\\main\\resources\\test.xml");
        SAXReader reader = new SAXReader();
        try {
            org.dom4j.Document document = reader.read(file);
            Element rootElement = document.getRootElement();
            Element foo;
            for (Iterator i = rootElement.elementIterator("value"); i.hasNext();){
                foo = (Element) i.next();
                System.out.print("车牌号码:" + foo.elementText("No"));
                System.out.println("车主地址:" + foo.elementText("Addr"));
            }
        } catch (DocumentException pE) {
            pE.printStackTrace();
        }
    }
}
